import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        scanner.nextLine();  // 消耗换行符
        for (int i = 0; i < T; i++) {
            // 加密字符串
            String s = scanner.next();
            System.out.println(fun(s));
        }
    }

    private static String fun(String s) {
        // 解密
        StringBuilder t = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == 'Z') {
                if (!t.isEmpty()) {
                    if (s.charAt(i - 1) == 'R') {
                        // 撤销 -> 再反转
                        StringBuilder tmp = new StringBuilder(t.substring(0, i - 1));
                        tmp.reverse();
                        t = tmp;
                    } else {
                        t.delete(t.length() - 1, t.length());
                    }
                }
            } else if (c == 'R') {
                // 反转
                StringBuilder tmp = new StringBuilder(t.substring(0, i));
                tmp.reverse();
                t = tmp;
            } else {
                t.append(c);
            }

        }
        return t.toString();
    }
}
